package com.hxgz.config;

import com.hxgz.Interceptor.LoginInterceptor;
import com.hxgz.filter.JwtFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

 /* @Autowired
  private LoginInterceptor loginInterceptor;*/

  @Autowired
  JwtFilter jwtFilter;

  protected void addInterceptors(InterceptorRegistry registry) {
    //注册声明 拦截器对象和拦截的请求
    registry.addInterceptor(jwtFilter)
        .addPathPatterns("/**")
        .excludePathPatterns("/**/userLogin.do/**", "/**/getSMS.do/**")
        .excludePathPatterns("/swagger-resources/**", "/webjars/**",
            "/swagger-ui.html/**");
  }

  @Override
  protected void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("swagger-ui.html")
        .addResourceLocations("classpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**")
        .addResourceLocations("classpath:/META-INF/resources/webjars/");
  }


}
